<template>
  <div class="tab_control">
    <div v-for="(item,index) in titles" :key="index" 
         class="tab-control-item"
         :class="{active: index === currentIndex}"
         @click="itemClick(index)">
      <span>{{item}}</span>
    </div>
  </div>
</template>

<script>

  export default {
    name: "TabControl",
    props: {
      titles: {
        type: Array,
        default() {
          return []
        }
      }
    },
    data() {
      return {
        currentIndex: 0
      }
    },
    methods: {
      itemClick(index) {
        this.currentIndex = index
        if(index == 0){
          this.$router.replace('/home/takeaway')
        }
        else if(index == 1){
          this.$router.replace('/home/necessary')
        }
        else{
          this.$router.replace('/home/fresh')
        }
      }
    }
  }
</script>

<style scoped>

  .tab_control{
    display: flex;
    text-align: center;
    font-size: 15px;
    height: 40px;
    line-height: 40px;
    background-color: #fff;
    z-index: 9;
  }

  .tab-control-item{
    flex: 1;
    /* background-color: #fff; */
  }

  .tab-control-item span{
    padding: 5px;
  }

  .active{
    color: #64b587;
  }

  .active span {
    border-bottom: 2px solid #64b587;
  }

</style>